package wwl.lsf.tools;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import wwl.lsf.hellospringboot.easyExcel.TestFileUtil;

import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class 加班时间计算 {

    /**
     * 获取指定年月有多少个bai工作日）
     * @param year
     * @param month
     */
    public static int countWorkDay(int year,int month,int start) {
        Calendar c = Calendar.getInstance();
        c.set(Calendar.YEAR, year);
        // 月份是从0开始du计算，所以需要减去1
        c.set(Calendar.MONTH,month-1);
        // 当月最后一天的日期dao
        int max = c.getActualMaximum(Calendar.DAY_OF_MONTH);
        // 开始日期为传入
        // 计数
        int count = 0;
        while(start <= max){
            c.set(Calendar.DAY_OF_MONTH,start);
            if(isWorkDay(c)){
                count++;
            }
            start++;
        }
        return count;
    }
    // 判断是否工作日（未排除法定节假日，由于涉及到农历节日，处理很麻烦）
    public static boolean isWorkDay(Calendar c){
        // 获取星期,1~7,其中1代表星期日，2代表星期一 ... 7代表星期六
        int week = c.get(Calendar.DAY_OF_WEEK);
        // 不是周六和周日的都认为是工作日
        return week != Calendar.SUNDAY  && week != Calendar.SATURDAY;
    }
    public static void main(String[] args) {

//        int i = countWorkDay(2023, 03, 23);
//        System.out.println("i = " + i);

        LocalDate now1 = LocalDate.now();

        int year = now1.getYear();
        System.out.println("year = " + year);
        int monthValue = now1.getMonthValue();
        System.out.println("monthValue = " + monthValue);
        int dayOfMonth = now1.getDayOfMonth();
        System.out.println("dayOfMonth = " + dayOfMonth);

    }

    private static List<考勤VO> data() {
        String data = "";

        JSONObject parse = JSON.parseObject(data);
        JSONObject data1 = (JSONObject) parse.get("data");
//        JSONArray days = (JSONArray) data1.get("days");
        List<考勤VO> voList = JSON.parseArray(JSON.toJSONString(data1.get("days")), 考勤VO.class);//转换成vo
        for (考勤VO vo : voList) {
            if (vo.getNormalNotes()!=null) {
                System.out.println(vo.getNormalNotes());
            }


            if (vo.getPunchBegin() != null && vo.getPunchBegin().getHours() > 9) {
                vo.getPunchBegin().setHours(9);
                vo.getPunchBegin().setMinutes(0);
                vo.getPunchBegin().setSeconds(0);
            }
            if (vo.getPunchEnd() != null && vo.getPunchEnd().getHours() < 18) {
                vo.getPunchEnd().setHours(18);
                vo.getPunchEnd().setMinutes(0);
                vo.getPunchEnd().setSeconds(0);
            }
            if (vo.getPunchBegin() != null && vo.getPunchEnd() != null) {
                long begin = vo.getPunchBegin().getTime();
                long end = vo.getPunchEnd().getTime();
                long a = (end - begin - 1000 * 60 * 60 * 9L) / 1000 / 60;
                vo.setJiabanshichang(a);
            }
        }


        return voList;
    }
}
